﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Tour.BLL;
using Tour.DAL;

public partial class Admin_Modules_Event_EventTypeAE : VST.Controls.BaseLCGPage
{
    public int? EventTypeId { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        EventTypeId = CommonHelper.QueryStringInt("EventTypeId", null);
        if (!IsPostBack)
        {          
            LoadData();
        }
    }
    void LoadData()
    {
        if (EventTypeId.HasValue)
        {
            TblEventTypeEntity item = TblEventTypeManager.CreateInstant().SelectOne(EventTypeId.Value);
            txtName.Text = item.Name;            
            txtKeywords.Text = item.Keywords;
            txtDescription.Text = item.Description;           
            chkVisible.Checked = item.IsVisible;
        }
    }
    TblEventTypeEntity GetTblEventType()
    {
        TblEventTypeEntity item = new TblEventTypeEntity();
        if (EventTypeId.HasValue)
        {
            item = TblEventTypeManager.CreateInstant().SelectOne(EventTypeId.Value);
            item.UpdatedBy = User.Identity.Name;
            item.UpdatedDate = DateTime.Now;
        }
        else
        {
            item.TextId = TblEventTypeManager.CreateInstant().GetUniqueTextIdFromUnicodeText(txtName.Text);
            item.DisplayOrder = 1;
            item.CreatedBy = User.Identity.Name;
            item.CreatedDate = DateTime.Now;
            item.UpdatedBy = User.Identity.Name;
            item.UpdatedDate = DateTime.Now;
        }
        item.LanguageId = WorkingLanguage;
        item.IsVisible = chkVisible.Checked;
        item.Name = txtName.Text;       
        item.Description = txtDescription.Text;
        item.Keywords = txtKeywords.Text;
        return item;
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        TblEventTypeManager.CreateInstant().InsertUpdate(GetTblEventType());
        Response.Redirect("EventTypeList.aspx");
    }
    private void UpdateOrderOffAndDelete(string strId, string strParentId, int NewIndex)
    {
        string Whereclause = " And ParentId IS NULL ";        
        string Whereclause1 = String.Format(" ID={0}", strId);
        string Whereclause2 = String.Format(" And Id<>{0}", strId);
        Tools.SqlHelper.UpdateOrders("TblEventType", Whereclause, Whereclause1, Whereclause2, NewIndex);
    }
}